/*
 * @Author: Await
 * @Date: 2025-04-17 15:19:25
 * @LastEditors: Await
 * @LastEditTime: 2025-05-08 10:11:17
 * @Description: 数据相关类型定义
 */

/**
 * 单个数据项
 */
export interface DataItem {
    [key: string]: any; // Flexible structure
}

/**
 * 数据源对象
 */
export interface DataSourceInfo { // Renamed from DataSource to avoid conflict if imported elsewhere
    id?: string;
    name?: string;
    data: DataItem[];
    type?: 'json' | 'csv' | 'array'; // Type of original source if known
    updatedAt?: Date;
}

/**
 * 数据维度定义
 */
export interface DimensionField {
    field: string; // Field name in DataItem
    name: string; // Display name
    xAxis?: boolean; // Role: Is this the primary X axis?
    yAxis?: boolean; // Role: Is this the primary Y axis?
    seriesName?: boolean; // Role: Does this field define series names?
    tooltip?: boolean; // Role: Include in tooltip?
    category?: boolean; // Role: 是否为分类维度(用于饼图等)
    // Add other potential roles or properties
}

/**
 * 数据度量定义
 */
export interface MeasureField {
    field: string; // Field name in DataItem
    name: string; // Display name
    aggregation?: 'sum' | 'avg' | 'max' | 'min' | 'count'; // Optional aggregation
    primary?: boolean; // 是否为主要度量，通常用于Y轴或数值映射
    // Add other properties like formatting, unit etc.
}

/**
 * 编辑器内的数据配置状态
 * Defines how raw data items are mapped to chart dimensions/measures
 */
export interface DataConfig {
    // source?: DataSourceInfo; // Link back to original source if needed
    dimensions: DimensionField[]; // Fields acting as categories, axes, series names
    measures: MeasureField[]; // Fields acting as numerical values

    // 传统映射方式兼容
    category?: string; // 映射到分类/名称的字段
    value?: string; // 映射到数值的字段
    series?: string; // 映射到系列的字段
    extraFields?: string[]; // 额外需要保留的字段

    // Mappings might be an alternative or supplement to dimensions/measures
    // mappings?: DataFieldMapping[];
    // Optional transformation steps
    filterConditions?: Array<{
        field: string;
        operator: string; // e.g., '= ', '>', '<', 'contains'
        value: any;
    }>;
    sortBy?: {
        field: string;
        order: 'asc' | 'desc';
    };
}
